home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 48973 / 48973.xpi / chrome / toolbarbutton.js < prev    next >
Text File  |  2010-02-09  |  2KB  |  50 lines

  1. var DownloadFolderToolbarButton = {
  2.     onToolbarButtonCommand: function(e) {
  3.         DownloadFolderToolbarButton.openDownloadFolder();
  4.     },
  5.     openDownloadFolder : function() {
  6.         var pref = Components.classes["@mozilla.org/preferences-service;1"]
  7.                                 .getService(Components.interfaces.nsIPrefBranch);
  8.             
  9.             var dirService = Components.classes["@mozilla.org/file/directory_service;1"].
  10.                                         getService(Components.interfaces.nsIProperties);
  11.             
  12.             if(pref.getBoolPref("browser.download.useDownloadDir")) {
  13.             // Firefox is going to check where to save by file according to the folderList
  14.                 switch (pref.getIntPref("browser.download.folderList")) {
  15.                     case 0: // the desktop
  16.                     var desktop = dirService.get("Desk", Components.interfaces.nsILocalFile);
  17.                     folder = desktop;
  18.                     break;
  19.                 case 1: // the downloads folder
  20.                     var dm = Components.classes["@mozilla.org/download-manager;1"]
  21.                        .getService(Components.interfaces.nsIDownloadManager);
  22.  
  23.                     folder = dm.userDownloadsDirectory;
  24.                     
  25.                     break;
  26.                 case 2: // the last folder specified for a download
  27.                     folder = pref.getComplexValue("browser.download.dir", Components.interfaces.nsILocalFile);
  28.                     break;
  29.                 }
  30.             
  31.             } else {
  32.                 // Users are manually pointing out a directory to save to
  33.                 folder = pref.getComplexValue("browser.download.lastDir", Components.interfaces.nsILocalFile);
  34.             }
  35.             
  36.             if (folder) {
  37.                 try {
  38.                     folder.reveal();
  39.                 } catch (ex) {
  40.                     // if nsILocalFile::Reveal failed (eg it currently just returns an
  41.                     // error on unix), just open the folder in a browser window
  42.                     alert(ex);
  43.                 }
  44.             } else {
  45.                 alert("Unable to open folder, please contact me at wybren@zen-ben.com!");
  46.             }
  47.     }
  48. }
  49.  
  50.